package com.enation.app.javashop.api.client;

import com.enation.app.javashop.model.member.dos.ReceiptHistory;
import com.enation.app.javashop.model.member.vo.ReceiptHistoryVO;
import com.enation.app.javashop.service.member.ReceiptHistoryManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 会员历史发票api
 *
 * @author zh
 * @version v7.0
 * @date 18/7/30 下午8:10
 * @since v7.0
 */
@Api(description = "会员历史发票api")
@RestController
@RequestMapping("/client/members/receipt-history")
@Validated
@ApiIgnore
public class MembeReceitHistoryClientController {

    @Autowired
    private ReceiptHistoryManager receiptHistoryManager;

    @ApiOperation(value = "根据订单号查询发票历史", response = ReceiptHistory.class)
    @GetMapping("/{order_sn}")
    @ApiImplicitParam(name = "order_sn", value = "订单sn", required = true, dataType = "String", paramType = "path")
    public ReceiptHistoryVO getMemberAddress(@ApiIgnore @PathVariable("order_sn") String orderSn) {
        return receiptHistoryManager.getReceiptHistory(orderSn);
    }

    @PostMapping
    public ReceiptHistory add(@RequestBody ReceiptHistory receiptHistory) {
        return receiptHistoryManager.add(receiptHistory);
    }

    @PostMapping("/edit")
    public ReceiptHistory edit(@RequestBody ReceiptHistory receiptHistory) {
        return receiptHistoryManager.edit(receiptHistory, receiptHistory.getHistoryId());
    }

    @RequestMapping(value = "/update-price", method = RequestMethod.POST)
    public void updatePriceByOrderSn(@RequestParam("order_price") Double orderPrice, @RequestParam("order_sn")String orderSn){

        receiptHistoryManager.updatePriceByOrderSn(orderPrice, orderSn);
    }


}
